# -*- encoding:utf-8 -*-
# @Time: 2022/11/2 11:14
# @Author : renyuxuan
# @Email: renyuxuan@maqu.com
# @File: serializers.py
# @Software: PyCharm

from django.contrib.auth.models import User
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from users.models import *


class UserDetailSerializer(ModelSerializer):
    class Meta:
        model = UserDetail
        exclude = ['is_delete']
        extra_kwargs = {
            'avatar': {'read_only': True},
            'user': {'required': False, 'write_only':True}
        }


class UserSerializer(ModelSerializer):
    userdetail = UserDetailSerializer(required=False, read_only=True)

    class Meta:
        model = User
        exclude = ['password','last_name']

    extra_kwargs = {
        'id': {'read_only': True},
        'last_login': {'read_only': True},
        'is_superuser': {'read_only': True},
        'is_staff': {'read_only': True},
        'is_active': {'read_only': True},
        'groups': {'read_only': True},
        'date_joined': {'read_only': True},
    }